package com.example.tilas1.controller;

import com.example.tilas1.pojo.Dept;
import com.example.tilas1.pojo.response.Result;
import com.example.tilas1.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    DeptService deptService;

    @PostMapping
    public Result deptinsert(@RequestBody Dept dept) {
        deptService.insert(dept);
        return Result.success();
    }

    /**
     * 查询全部部门
     *
     * @return
     */
    @GetMapping
    public Result<List<Dept>> deptselect() {
        List<Dept> dept = deptService.select();
        return Result.success(dept);
    }

    /**
     * 删除部门
     *
     * @param id
     * @return
     */

    @DeleteMapping()
    public Result delete(Integer id) {
        deptService.delete(id);
        return Result.success();
    }
}
